package com.welbell.android.test.camera;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

	private SurfaceView surfaceView;
	private Button startCameraPreviewButton;
	private Button stopCameraPreviewButton;

	private CameraVideoRecoder cameraVideoRecoder;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
		startCameraPreviewButton = (Button) findViewById(R.id.startCameraPreviewButton);
		stopCameraPreviewButton = (Button) findViewById(R.id.stopCameraPreviewButton);

		startCameraPreviewButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				log("Press StartPreviewButton");

				if (cameraVideoRecoder == null) {
					cameraVideoRecoder = new CameraVideoRecoder(surfaceView);
				}
				cameraVideoRecoder.startCameraPreview();
			}
		});
		stopCameraPreviewButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				log("Press StopPreviewButton");

				if (cameraVideoRecoder != null) {
					cameraVideoRecoder.stopCameraPreview();
				}
			}
		});

	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
		if (cameraVideoRecoder != null) {
			cameraVideoRecoder.release();
		}
	}

	private void log(String _log) {
		Log.v("MainActivity", "    ----    " + _log);
	}

}
